﻿using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FreeDream.Common
{
    /// <summary>
    /// 直接记录Nlog日志
    /// </summary>
    public sealed class QueenLogger
    {
        /// <summary>
        /// Nlog日志
        /// </summary>
        //private readonly Logger _log;
        private static QueenLogger _flashLog = new QueenLogger();
        private QueenLogger()
        {
            //_log = LogManager.GetCurrentClassLogger();
        }
        /// <summary>
        /// 实现单例
        /// </summary>
        /// <returns></returns>
        public static QueenLogger Instance()
        {
            return _flashLog;
        }
        public void Register()
        {
            //
        }
        public static ILogger GetLogger(string categoryName)
        {
            return LogManager.GetLogger(categoryName);
        }
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="message">日志文本</param>
        /// <param name="level">等级</param>
        /// <param name="ex">Exception</param>
        /// <param name="folder">文件夹</param>
        public void EnqueueMessage(string message, LogLevel level, Exception ex = null, string folder = null)
        {
            LogEventInfo lei = new LogEventInfo(level, folder, null, message, null, ex);
            lei.Properties["Folder"] = folder;
            lei.Properties["exception"] = ex;

            LogManager.GetCurrentClassLogger().Log(level, lei);
        }

        public static void Debug(string msg, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, LogLevel.Debug, ex);
        }

        public static void Debug(string msg, string folder, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, LogLevel.Debug, ex, folder);
        }

        public static void Error(string msg, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, LogLevel.Error, ex);
        }

        public static void Error(string msg, string folder, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, LogLevel.Error, ex, folder);
        }

        public static void Fatal(string msg, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, LogLevel.Fatal, ex);
        }

        public static void Fatal(string msg, string folder, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, LogLevel.Fatal, ex, folder);
        }

        public static void Info(string msg, string folder = null, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, LogLevel.Info, ex, folder);
        }

        public static void Warn(string msg, string folder = null, Exception ex = null)
        {
            Instance().EnqueueMessage(msg, LogLevel.Warn, ex, folder);
        }
    }
}
